<?php


namespace app\api\model\view;

use app\logic\model\view\OpusNumber_opus_userView as OpusNumber_opus_user;
class OpusNumber_opus_userView extends OpusNumber_opus_user
{
    function getList($param,$field,$limit,$order='id asc'){
        $list=$this
            ->alias('o')
            ->leftJoin('opus_series second_series','o.opus_second_series_id=second_series.id')
            ->whereNotNull('o.opus_number_nft')
            ->where(function($q) use ($param){
                if(check_request($param,"title")){
                    $q->whereLike("o.opus_title","%{$param['title']}%");
                }
                if(check_request($param,"opus_id")){
                    $q->where("o.opus_id","{$param['opus_id']}");
                }
                if(check_request($param,"opus_number_id")){//编号标识
                    $q->where("o.id","{$param['opus_number_id']}");
                }
                if(check_request($param,"writer_is_best_seller")){//畅销艺术家
                    $q->where("o.writer_is_best_seller","{$param['writer_is_best_seller']}");
                }
                if(check_request($param,"writer_name")){
                    $q->whereLike("o.writer_nickname|writer_true_name","%{$param['writer_name']}%");
                }
                if(check_request($param,"opus_number")){
                    $q->whereLike("o.number","%{$param['opus_number']}%");
                }
                if(check_request($param,"status")){
                    $q->where("o.status",$param['status']);
                }
                if(check_request($param,"is_owner")){
                    $q->where("o.owner_uid",'>',0);
                }
                if(check_request($param,"is_writer")){
                    $q->where("o.owner_uid",'=',0);
                }
                if(check_request($param,"owner_uid")){
                    $q->where("o.owner_uid",$param['owner_uid']);
                }
                if(check_request($param,"opus_series_id")){
                    $q->where("o.opus_series_id",$param['opus_series_id']);
                }
                if(check_request($param,'noIsShake')){
                    $q->where('second_series.is_shake',-1);//不显示在摇一摇作品里面的
                }
                if(check_request($param,'secondSeriesStatus')){
                    $q->where('second_series.status',1);
                }
            })
            ->field($field)
            ->order($order)
            ->paginate($limit);
        if(!$list->isEmpty()){
            return $list->toArray();
        }
        return $list;
    }
    function findByid($id){
        $item=$this->where("id",$id)->find();
        return $item;
    }
}